package com.gw.yunke.web;

import com.gw.yunke.domain.Institute;
import com.gw.yunke.domain.Specialty;
import com.gw.yunke.domain.dto.InstitutesResp;
import com.gw.yunke.domain.dto.ResultData;
import com.gw.yunke.domain.dto.SpecialtyQueryReq;
import com.gw.yunke.service.IInstituteService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "yunke")
public class InstituteController {

  @Autowired
  private IInstituteService instituteService;

  @RequestMapping(value = "/institutes", method = RequestMethod.POST)
  public ResultData<List<Institute>> getAllInstitute() {
    ResultData resultData = new ResultData();
    resultData.setCode(ResultData.OK);
    resultData.setMessage("ok");
    resultData.setData(instituteService.getInstitutes());
    return resultData;
  }

  @RequestMapping(value = "/specialtys", method = RequestMethod.POST)
  public ResultData<List<Specialty>> getSpecialtysByInstitutes(@RequestBody() SpecialtyQueryReq specialtyQueryReq) {
    ResultData resultData = new ResultData();
    resultData.setCode(ResultData.OK);
    resultData.setMessage("ok");
    if (!StringUtils.isEmpty(specialtyQueryReq.getInstituteCode()))
      if (!specialtyQueryReq.getInstituteCode().equals("-1"))
        resultData.setData(instituteService.getSpecialtyByInstitute(specialtyQueryReq.getInstituteCode()));
      else {
        resultData.setData(instituteService.getSpecialty());
      }
    else {
      resultData.setCode(ResultData.ERROR);
      resultData.setMessage("参数错误");
    }
    return resultData;
  }

  @RequestMapping(value = "/getAllInstitutes",method = RequestMethod.POST)
  public ResultData<List<InstitutesResp>> getAll(){
    ResultData resultData = new ResultData();
    resultData.setCode(ResultData.OK);
    resultData.setMessage("ok");

    resultData.setData(instituteService.getAllInfo());
    return resultData;
  }


}
